/*
 * Copyright (C) 2006  Antonie Struyk
 *
 * This file is part of MusicFlashCards.
 *
 *    Freetar Hero is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    MusicFlashCards is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with MusicFlashCards; if not, write to the Free Software
 *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
package com.antonstruyk.musicflashcards;

import java.util.List;
import java.util.ArrayList;

/**
 *
 * @author Anton
 */
public class Note implements Comparable<Note>{
    public static enum NoteType {NATURAL, SHARP, FLAT};
    
    public static Note[] ALL_NOTES = new Note[32];
    public static Note[] C_MAJOR_RIGHT_HAND = new Note[8];
    public static Note[] C_MAJOR_LEFT_HAND = new Note[8];
    
    static {
        //Setup the ALL_NOTES
        for(int i = 0; i < 32; i++){
            ALL_NOTES[i] = new Note(i, getNameOfIndex(i));
        }
        
        //Setup the RIGHT_HAND_BASIC
        for(int i = 0; i < 8; i++){
            C_MAJOR_RIGHT_HAND[i] = ALL_NOTES[i + 14];
        }
        
        //Setup the RIGHT_HAND_BASIC_OCTAVE
        for(int i = 0; i < 8; i++){
            C_MAJOR_LEFT_HAND[i] = ALL_NOTES[i + 7];
        }
    }
    
    private static String getNameOfIndex(int index){
        int modulus = index % 7;
        switch(modulus){
            case 0:
                return "C";
            case 1:
                return "D";
            case 2:
                return "E";
            case 3:
                return "F";
            case 4:
                return "G";
            case 5:
                return "A";
            case 6:
                return "B";
            default:
                return "?";
        }
    }
    
    private int number;
    private String name;
    private NoteType type;
    
    /** Creates a new instance of Note */
    private Note(int number, String name) {
        this.number = number;
        this.name = name;
        type = NoteType.NATURAL;
    }
    
    public int getNumber(){
        return number;
    }
    
    public String getName(){
        return name;
    }
    
    public String toString(){
        return name + " " + type;
    }
    
    public int hash(){
        return number;
    }
    
    public int compareTo(Note o){
        return new Integer(this.getNumber()).compareTo(o.getNumber());
    }
    
    public boolean equals(Object o){
        if(! (o instanceof Note)){
            return false;
        }
        
        return this.getNumber() == ((Note)o).getNumber();
    }
}
